﻿using Microsoft.AspNetCore.Razor.TagHelpers;
using Mt.Site.Core.BundlerMinifier;

namespace Mt.Site.Web.TagHelpers
{
    public class AppBundleTagHelper : TagHelper
    {
        private readonly IBundlerHelper _bundlerHelper;

        public AppBundleTagHelper(IBundlerHelper bundlerHelper)
        {
            _bundlerHelper = bundlerHelper;
        }

        public string AspBundleName { get; set; }

        public bool AspIsRtl { get; set; }

        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            string content;
            if (AspBundleName.Contains(".css"))
            {
                content = _bundlerHelper.RenderStyles(AspBundleName, AspIsRtl);
            }
            else
            {
                content = _bundlerHelper.RenderScripts(AspBundleName);
            }
            output.TagName = null;
            output.Content.SetHtmlContent(content);
        }
    }
}
